# vim: filetype=sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.

. $STF_SUITE/tests/cli_root/cli.cfg
. $STF_SUITE/include/libtest.kshlib

export STF_TIMEOUT=1800

# We need to determine which version of ZFS we're running on, so as to
# work out which types of pool we should be able to upgrade on this
# system.
export ZPOOL_VERSION=$(get_zpool_version)


# The following variable names describe files, stored as gzip compressed files
# in the test directory which can be used to construct a pool of a given
# version. The variable names are important, in that the construction 
# ZPOOL_VERSION_$var_FILES describes the files the pool is made from, and
# ZPOOL_VERSION_$var_NAME describes the pool name.

# Version 1 pools
export ZPOOL_VERSION_1_FILES="zfs-pool-v1.dat"
export ZPOOL_VERSION_1_NAME="v1-pool"
# v1 stripe
export ZPOOL_VERSION_1stripe_FILES="zfs-pool-v1stripe1.dat \
zfs-pool-v1stripe2.dat  zfs-pool-v1stripe3.dat"
export ZPOOL_VERSION_1stripe_NAME="pool-v1stripe"
# v1 raidz
export ZPOOL_VERSION_1raidz_FILES="zfs-pool-v1raidz1.dat zfs-pool-v1raidz2.dat \
zfs-pool-v1raidz3.dat"
export ZPOOL_VERSION_1raidz_NAME="pool-v1raidz"
# v1 mirror
export ZPOOL_VERSION_1mirror_FILES="zfs-pool-v1mirror1.dat \
zfs-pool-v1mirror2.dat zfs-pool-v1mirror3.dat"
export ZPOOL_VERSION_1mirror_NAME="pool-v1mirror"


# Version 2 pools
export ZPOOL_VERSION_2_FILES="zfs-pool-v2.dat"
export ZPOOL_VERSION_2_NAME="v2-pool"
# v2 stripe
export ZPOOL_VERSION_2stripe_FILES="zfs-pool-v2stripe1.dat \
zfs-pool-v2stripe2.dat  zfs-pool-v2stripe3.dat"
export ZPOOL_VERSION_2stripe_NAME="pool-v2stripe"
# v2 raidz
export ZPOOL_VERSION_2raidz_FILES="zfs-pool-v2raidz1.dat zfs-pool-v2raidz2.dat \
zfs-pool-v2raidz3.dat"
export ZPOOL_VERSION_2raidz_NAME="pool-v2raidz"
# v2 mirror
export ZPOOL_VERSION_2mirror_FILES="zfs-pool-v2mirror1.dat \
zfs-pool-v2mirror2.dat zfs-pool-v2mirror3.dat"
export ZPOOL_VERSION_2mirror_NAME="pool-v2mirror"


# This is a v3 pool
export ZPOOL_VERSION_3_FILES="zfs-pool-v3.dat"
export ZPOOL_VERSION_3_NAME="v3-pool"
# v3 stripe
export ZPOOL_VERSION_3stripe_FILES="zfs-pool-v3stripe1.dat \
zfs-pool-v3stripe2.dat  zfs-pool-v3stripe3.dat"
export ZPOOL_VERSION_3stripe_NAME="pool-v3stripe"
# v3 raidz
export ZPOOL_VERSION_3raidz_FILES="zfs-pool-v3raidz1.dat zfs-pool-v3raidz2.dat \
zfs-pool-v3raidz3.dat"
export ZPOOL_VERSION_3raidz_NAME="pool-v3raidz"
# v3 mirror
export ZPOOL_VERSION_3mirror_FILES="zfs-pool-v3mirror1.dat \
zfs-pool-v3mirror2.dat zfs-pool-v3mirror3.dat"
export ZPOOL_VERSION_3mirror_NAME="pool-v3mirror"
# v3 raidz2
export ZPOOL_VERSION_3dblraidz_FILES="zfs-pool-v3raidz21.dat \
zfs-pool-v3raidz22.dat zfs-pool-v3raidz23.dat"
export ZPOOL_VERSION_3dblraidz_NAME="pool-v3raidz2"
# v3 hotspares
export ZPOOL_VERSION_3hotspare_FILES="zfs-pool-v3hotspare1.dat \
zfs-pool-v3hotspare2.dat zfs-pool-v3hotspare3.dat"
export ZPOOL_VERSION_3hotspare_NAME="pool-v3hotspare"

# v4 pool
export ZPOOL_VERSION_4_FILES="zfs-pool-v4.dat"
export ZPOOL_VERSION_4_NAME="v4-pool"

# v5 pool
export ZPOOL_VERSION_5_FILES="zfs-pool-v5.dat"
export ZPOOL_VERSION_5_NAME="v5-pool"

# v6 pool
export ZPOOL_VERSION_6_FILES="zfs-pool-v6.dat"
export ZPOOL_VERSION_6_NAME="v6-pool"

# v7 pool
export ZPOOL_VERSION_7_FILES="zfs-pool-v7.dat"
export ZPOOL_VERSION_7_NAME="v7-pool"

# v8 pool
export ZPOOL_VERSION_8_FILES="zfs-pool-v8.dat"
export ZPOOL_VERSION_8_NAME="v8-pool"

# v9 pool
export ZPOOL_VERSION_9_FILES="zfs-pool-v9.dat"
export ZPOOL_VERSION_9_NAME="v9-pool"

# v10 pool
export ZPOOL_VERSION_10_FILES="zfs-pool-v10.dat"
export ZPOOL_VERSION_10_NAME="v10-pool"

# v11 pool
export ZPOOL_VERSION_11_FILES="zfs-pool-v11.dat"
export ZPOOL_VERSION_11_NAME="v11-pool"

# v12 pool
export ZPOOL_VERSION_12_FILES="zfs-pool-v12.dat"
export ZPOOL_VERSION_12_NAME="v12-pool"

# v13 pool
export ZPOOL_VERSION_13_FILES="zfs-pool-v13.dat"
export ZPOOL_VERSION_13_NAME="v13-pool"

# v14 pool
export ZPOOL_VERSION_14_FILES="zfs-pool-v14.dat"
export ZPOOL_VERSION_14_NAME="v14-pool"

# v15 pool
export ZPOOL_VERSION_15_FILES="zfs-pool-v15.dat"
export ZPOOL_VERSION_15_NAME="v15-pool"

# v28 pool
export ZPOOL_VERSION_28_FILES="zfs-pool-v28.dat"
export ZPOOL_VERSION_28_NAME="v28-pool"

# v5000 pool
export ZPOOL_VERSION_5000_FILES="zfs-pool-v5000.dat"
export ZPOOL_VERSION_5000_NAME="v5000-pool"

# This pool is a v2 pool, with device problems on one side of the mirror
# so that the pool appears as DEGRADED
export ZPOOL_VERSION_2brokenmirror_FILES="zfs-broken-mirror1.dat \
zfs-broken-mirror2.dat"
export ZPOOL_VERSION_2brokenmirror_NAME="zfs-broken-mirror"


# This pool is a v999 pool (an unknown version) which can be used to check
# whether upgrade, import or other tests that should fail against unknown
# pool versions should fail. It should not be listed in the CONFIGS
# variable below, as these are pool versions that can be imported and upgraded
export ZPOOL_VERSION_9999_FILES="zfs-pool-v999.dat"
export ZPOOL_VERSION_9999_NAME="v999-pool"


# This statement builds up a list of configurations we should be able to
# upgrade, for each pool version. Once we've built this variable, we'll
# call the functions above for each value.
case $ZPOOL_VERSION in
1)
	# we should be able to upgrade pools of version 1
	CONFIGS="1 1stripe 1raidz 1mirror"
	;;
	
2)
	# we should be able to upgrade pools of version 1 & 2
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror"
	;;
3)
	# we should be able to upgrade pools of version 1, 2 & 3
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare"
	;;
4)
	# we should be able to upgrade pools of version 1, 2, 3 & 4
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4"
	;;
5)
	# we should be able to upgrade pools up to version 5
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5"
	;;
6)
	# we should be able to upgrade pools up to version 6
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6"
	;;
7)
	# we should be able to upgrade pools up to version 7
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7"
	;;
8)
	# we should be able to upgrade pools up to version 8
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8"
	;;
9)
	# we should be able to upgrade pools up to version 9
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9"
	;;
10)
	# we should be able to upgrade pools up to version 10 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10"
	;;
11)
	# we should be able to upgrade pools up to version 11 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11"
	;;
12)
	# we should be able to upgrade pools up to version 12 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12"
	;;
13)
	# we should be able to upgrade pools up to version 13 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13"
	;;
14)
	# we should be able to upgrade pools up to version 14 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14"
	;;
15)
	# we should be able to upgrade pools up to version 15 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15"
	;;
28)
	# we should be able to upgrade pools up to version 15 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15 28"
	;;
5000)
	# we should be able to upgrade pools up to version 15 
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15 28 5000"
	;;
*)
	# we should be able to upgrade pools up to version 15
	# but we should also log a note about the unknown pool version
	CONFIGS="1 1stripe 1raidz 1mirror \
	2 2stripe 2raidz 2mirror 2brokenmirror \
	3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15"

	log_note "Unknown ZFS version $ZPOOL_VERSION encountered:\
		Test suite may need updating."
	;;
esac
export CONFIGS
